package tech.aistar.design.factory.version06;

import tech.aistar.day06.extend.Dog;
import tech.aistar.design.factory.version05.Sender;

/**
 * 本类用来演示: 反射工厂
 *
 * @author: success
 * @date: 2021/3/16 4:48 下午
 */
public class BeanFactory {

    public static Object getInstance(String className){
        Object obj = null;
        //1. 获取class实例
        try {
            Class<?> c = Class.forName(className);
            obj = c.newInstance();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        }
        return obj;
    }
}

class TestBean{
    public static void main(String[] args) {
        Dog dog = (Dog) BeanFactory.getInstance("tech.aistar.day06.extend.Dog");
    }
}
